<?php
namespace Home\Controller;
use OT\DataDictionary;
class IndexController extends HomeController {
    public function index(){
        $shopa=M('shop');
      	$category=D('Category');
      	$tree = $category->getTree();
        $s=$shopa->order('rand()')->limit(3)->select();
        $zs=$shopa->order('addtime',desc)->limit(10)->select();
        $ss=$shopa->where(array('status'=>1))->limit(10)->select();
        $friend=M('friends')->limit(10)->select();
        $input=array_slice($ss,0,4);
        $inp=array_slice($zs,0,4);
        $t = M('category')->where('pid='.$tree[2]['id'])->select();
      foreach ($t as $k => $v) {
        $g = M('Category')->where(array('pid'=>$v['id']))->select();
          foreach ($g as $k => $v) {
            $shop = $shopa->where(array('cate'=>$v['id']))->select();
            foreach ($shop as $k=> $v) {
             $shops=array();
             $shops[].=$v['title'];
             $shops[].=$v['pic'];
             $shops[id].=$v['id'];
             $pric=array();
             $price = M('price')->where(array('pid'=>$v['id']))->select();
              foreach ($price as $a) {
             $pric[].=$a['sprice'];     
              }
               $min=min($pric);
               $shops[]=$min;
               $sho[]=$shops;
            }
          }
      }
        foreach ($inp as $v) {
            $pricinput=array();
            $price = M('price')->where(array('pid'=>$v['id']))->select();
            $pricess=array();
            foreach ($price as $c) {
            $pricess[].=$c['sprice'];
          }
            $min=min($pricess);
            $pricinput[]= $min;
            $io[]=$pricinput[0];
        }
        foreach ($input as $v) {
          $pricinput=array();
          $price = M('price')->where(array('pid'=>$v['id']))->select();
          $prices=array();
          foreach ($price as $c) {
            $prices[].=$c['sprice'];
          }
            $min=min($prices);
            $pricinput[]= $min;
            $ior[]=$pricinput[0];
        }
        $this->assign('io',$io);
        $this->assign('ior',$ior);
        $this->assign('friend',$friend);
        $this->assign('inp',$inp);
        $this->assign('input',$input);
        $this->assign('ss',$ss);
        $this->assign('zs',$zs);
        $this->assign('s',$s);
        $this->assign('sho',$sho);
        $this->assign('tree', $tree);
        $this->display();
    }
}